package com.ruoyi.business.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.ruoyi.business.domain.TOrderInfo;
import com.ruoyi.business.response.ResponseData;
import com.ruoyi.business.service.BasePayment;
import com.ruoyi.common.constant.GlobalConstants;
import com.ruoyi.common.utils.MoneyUtil;
import com.ruoyi.system.service.ISysConfigService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.net.URLEncoder;

@Slf4j

@Service("alipayzhzzPayService")
public class AlipayZhzzServiceImpl  extends BasePayment {


    @Autowired
    public ISysConfigService sysConfigService;

    @Override
    public JSONObject createPayOrder(TOrderInfo orderInfo)throws Exception  {
        JSONObject jsonObject = new JSONObject();
        String nginxPayGateway = sysConfigService.selectConfigByKey("sys.bussine.nginxPayGateway");
        String secpayUrl = nginxPayGateway + GlobalConstants.API_BASE_URL + "alipayzhzz?p=" + orderInfo.getId();

        String payUrl = "alipays://platformapi/startapp?appId=09999988&actionType=toAccount&amount="+ MoneyUtil.fenToYuan(orderInfo.getMoney()+"")+"&memo="+orderInfo.getId();
        String aliUrl = "alipays://platformapi/startapp?appId=20000067&url=" + URLEncoder.encode(secpayUrl);// URLEncoder.encode(url);
//        payUrl = "https://ds.alipay.com/?scheme=" + URLEncoder.encode(aliUrl);
        jsonObject.put("payUrl",aliUrl);
        jsonObject.put("orderNo",orderInfo.getId());
        jsonObject.put("code","200");
        return jsonObject;
    }


    @Override
    public ResponseData smartReissueOrder(TOrderInfo orderInfo) throws Exception {
        return null;
    }
}
